<%@ page language="java" contentType="text/html;charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html lang="zh_CN">
<head>
<%@ include file="../common/header.jsp"%>
</head>
<body>

	<div class="container " style="margin-top: 20px">
		<%@ include file="../common/top.jsp"%>

		<div class="row">
			<div class="col-sm-3">
				<c:set var="menu" value="department" />
				<%@ include file="../common/menu.jsp"%>
			</div>
			<div class="col-sm-9">
				<div class="row">
					<div class="col-sm-12">
						<h1 class="page-head-line">部门管理</h1>
					</div>
				</div>

				<form class="form-inline" id="searchForm"
					action="/department/list.do" method="post">
					<input type="hidden" name="currentPage" id="currentPage" value="1">
					<a role="button" class="btn btn-success inputBtn"> <span
						class="glyphicon glyphicon-plus"></span> 添加
					</a>
				</form>

				<table class="table table-striped table-hover">
					<tr>
						<th>编号</th>
						<th>部门名称</th>
						<th>部门编码</th>
						<th>操作</th>
					</tr>
					<c:forEach var="entity" items="${pageInfo.list}">
						<tr>
							<td>${entity.id}</td>
							<td>${entity.name}</td>
							<td>${entity.sn}</td>
							<td><a role="button" class="btn btn-info btn-xs inputBtn"
								data-json='${entity.json}'> <span
									class="glyphicon glyphicon-pencil"></span> 编辑
							</a> <a role="button"
								data-url="/department/delete.do?id=${entity.id}"
								class="btn btn-danger btn-xs deleteBtn"> <span
									class="glyphicon glyphicon-trash"></span> 删除
							</a></td>
						</tr>
					</c:forEach>
				</table>
				<%@ include file="../common/page.jsp"%>
			</div>
		</div>
	</div>

	<!-- 模态框 -->
	<div class="modal fade" id="departmentModal" tabindex="-1"
		role="dialog" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">&times;</button>
					<h4 class="modal-title">编辑</h4>
				</div>
				<div class="modal-body">
					<!--填充编辑界面-->
					<form class="form-horizontal" action="/department/saveOrUpdate.do"
						method="post" id="editForm">
						<input type="hidden" name="id" />
						<div class="form-group">
							<label class="col-lg-4 control-label">部门名称：</label>
							<div class="col-lg-6">
								<input type="text" class="form-control" name="name"
									placeholder="请输入部门名称" />
							</div>
						</div>
						<div class="form-group">
							<label class="col-lg-4 control-label">部门编码：</label>
							<div class="col-lg-6">
								<input type="text" class="form-control" name="sn"
									placeholder="请输入部门编码" />
							</div>
						</div>
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					<button type="button" class="btn btn-primary departmentSubmitBtn">保存</button>
				</div>
			</div>
		</div>
	</div>

	<script>
		$(function() {
			$(".inputBtn").click(function() {
				$("#editForm input").val("");
				var json = $(this).data("json");
				if (json) {
					$("#editForm input[name='id']").val(json.id);
					$("#editForm input[name='name']").val(json.name);
					$("#editForm input[name='sn']").val(json.sn);
				}
				$("#departmentModal").modal("show");
			});

			$(".departmentSubmitBtn").click(function() {
				$("#editForm").submit();
			});
		});
	</script>
</body>
</html>